package cn.school;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

//jdbc
//import com.mysql.jdbc.Driver;

public class FirstJdbc {
	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			System.out.println("驱动没有找到!");
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		String url = "jdbc:mysql://localhost:3306/java67?useUnicode=true&characterEncoding=UTF8&useServerPrepStmts=true&prepStmtCacheSqlLimit=256&cachePrepStmts=true&prepStmtCacheSize=256&rewriteBatchedStatements=true&useSSL=false";
		try {
			Connection con = DriverManager.getConnection(url, "zhaoyang", "zhaoyang");
			System.out.println(con.getClass());
			Statement stmt = con.createStatement();
			System.out.println(stmt.getClass());
			ResultSet rs = stmt
					.executeQuery("select id,subjectname,classhour,gradeid from s_subject order by classhour desc");
			System.out.println(rs.getClass());
			while (rs.next()) {
				long id = rs.getLong("id");
				String name = rs.getString("subjectname");
				int hours = rs.getInt("classhour");
				long gradeid = rs.getLong("gradeid");
				System.out.printf("%d,%s,%d,%d\n", id, name, hours, gradeid);
			}
			// stmt.executeQuery("select * from s_grade");
			rs.close();
			stmt.close();
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
